﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using OnlineGameClient.ViewModel;

namespace OnlineGameClient.View
{
    public partial class GameView : UserControl
    {
        public GameView()
        {
            InitializeComponent();
            Loaded += new RoutedEventHandler(GameView_Loaded);
        }

        void GameView_Loaded(object sender, RoutedEventArgs e)
        {
            OpenGameUI();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var vm = this.DataContext as GameRoomViewModel;
            var state = vm.CurrentGameRoom.GameState;
            if (state == OnlineGameLibrary.Contract.GameState.Running)
            {
                var ret = MessageBox.Show("The game is still ongoing, are you sure to quit?", "warning", MessageBoxButton.OKCancel);
                if (ret == MessageBoxResult.OK)
                {
                    border1.Child = null;
                    //sv1.Content = null;
                    vm.LeaveGameRoomCommand.Execute(null);
                }
            }
            else
            {
                border1.Child = null;
                //sv1.Content = null;
                vm.LeaveGameRoomCommand.Execute(null);
            }
        }


        public void OpenGameUI()
        {
            var vm = this.DataContext as GameRoomViewModel;
            if (vm.CurrentGame != null)
                border1.Child = vm.CurrentGame.GameUI;
            //sv1.Content = vm.CurrentGame.GameUI;
            else
                border1.Child = null;
                //sv1.Content = null;
        }



        //public void CloseGameUI()
        //{
        //    border1.Child = null;
        //}
    }
}
